package no.ntnu.fp.comparators;

import java.util.Comparator;

public class CompareRoomReservations implements Comparator<String> {
	public int compare(String o1, String o2) {
		//return 0 hvis kollisjon
		// stringene er i format: 311212 00:00 00:00 (dato start slutt)
		String year1 = o1.substring(4, 6);
		String year2 = o2.substring(4, 6);
		int year1int = Integer.parseInt(year1);
		int year2int = Integer.parseInt(year2);
		
		
		if (year1int != year2int)
			return -1;
		
		int month1 = Integer.parseInt(o1.substring(2, 4));
		int month2 = Integer.parseInt(o2.substring(2, 4));
		
		if (month1 != month2)
			return -1;
		
		int day1 = Integer.parseInt(o1.substring(0, 2));
		int day2 = Integer.parseInt(o2.substring(0, 2));
		
		if (day1 != day2)
			return -1;
		
		//hvis man kommer hit er avtalene samme dag
		
		int startHour1 = Integer.parseInt(o1.substring(7, 9));
		int startMinute1 = Integer.parseInt(o1.substring(10, 12));
		
		int startHour2 = Integer.parseInt(o2.substring(7, 9));
		int startMinute2 = Integer.parseInt(o2.substring(10, 12));
		
		int stopHour1 = Integer.parseInt(o1.substring(13, 15));
		int stopMinute1 = Integer.parseInt(o1.substring(16, 18));
		
		int stopHour2 = Integer.parseInt(o2.substring(13, 15));
		int stopMinute2 = Integer.parseInt(o2.substring(16, 18));
		
		if ((stopHour1 < startHour2) || (startHour1 > stopHour2))
			return -1; //ny avtale ferdig f�r gammel starter eller omvendt
		
		if ((stopHour1 == startHour2) && (stopMinute1 <= startMinute2))
			return -1; 
		
		if ((startHour1 == stopHour2) && (startMinute1 >= stopMinute2))
			return -1;
		
		return 0;
	}
}
